package Algorithm;

public class Num695 {
    int[] dx={1,0,0,-1};
    int[] dy={0,-1,1,0};
    int m,n;
    public int maxAreaOfIsland(int[][] grid) {
        int count=0;
        m=grid.length;
        n=grid[0].length;
        for(int i=0;i<m;i++){
            for(int j=0;j<n;j++){
                if(grid[i][j]==1){
                    count=Math.max(count,dfs(grid,i,j));
                }
            }
        }
        return count;
    }
    private int dfs(int[][] grid,int i ,int j){
        if(i<0 || i>=m || j<0 || j>=n || grid[i][j]==0) return 0;
        grid[i][j]=0;
        int num=1;
        for(int k=0;k<4;k++){
            int x=i+dx[k];
            int y=j+dy[k];
            num+=dfs(grid,x,y);

        }
        return num;
    }
}
